﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CharmL {

    class Program {
        static void Main(string[] args) {
            //#region accidents
            //string fileName = "accidents.txt";
            //int increBatchSize = 600;
            //int increSize = 200;
            //int fileSize = 340183;
            //double minSup = 0.75;


            //int increTotalSize = 1200;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            //#region retail
            //string fileName = "retail.txt";
            //int increBatchSize = 500;
            //int increSize = 100;
            //int fileSize = 88162;
            //double minSup = 0.05;


            //int increTotalSize = 1000;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion
            //#region pumsb-start
            //string fileName = "pumsb_star.txt";
            //int increBatchSize = 500;
            //int increSize = 100;
            //int fileSize = 49046;
            ////double minSup = 0.6;
            //double minSup = 0.7;


            ////int increTotalSize = 1000;
            //int increTotalSize = 1000;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            //#region pumsb-start
            //string fileName = "pumsb_star.txt";
            //int increBatchSize = 500;
            //int increSize = 100;
            //int fileSize = 49046;
            ////double minSup = 0.6;
            //double minSup = 0.7;


            ////int increTotalSize = 1000;
            //int increTotalSize = 500;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion
            #region pumsb
            string fileName = "pumsb.txt";
            int increBatchSize = 1600;
            int increSize = 200;
            int fileSize = 49046;
            double minSup = 0.96;


            int increTotalSize = 3000;

            int ReadNumTrans = fileSize - increTotalSize;
            #endregion
            //#region pumsb
            //string fileName = "pumsb.txt";
            //int increBatchSize = 500;
            //int increSize = 100;
            //int fileSize = 49046;
            //double minSup = 0.96;


            //int increTotalSize = 1000;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion
            //#region Connect
            //string fileName = "connect.txt";
            //int increBatchSize = 500;
            //int increSize = 100;
            //int fileSize = 67557;
            //double minSup = 0.98;


            //int increTotalSize = 1000;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            //#region Chess test - fails
            //string fileName = "chess.txt";
            //int increBatchSize = 100;
            //int increSize = 25;
            //int fileSize = 3196;
            //double minSup = 0.9;


            //int increTotalSize = 200;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            //#region Chess test - fails
            //string fileName = "chess.txt";
            //int increBatchSize = 100;
            //int increSize = 25;
            //int fileSize = 3196;
            //double minSup = 0.9;


            //int increTotalSize = 200;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            //#region Mushroom test
            //string fileName = "mushrooms.txt";
            //int increBatchSize = 200;
            //int increSize = 50;
            //int fileSize = 8416;
            //double minSup = 0.25;


            //int increTotalSize = 400;

            //int ReadNumTrans = fileSize - increTotalSize;
            //#endregion

            ReadNumTrans = OnlyCharmL(args, fileName, fileSize, minSup, increSize, ReadNumTrans);

            ReadNumTrans = TestIncre(args, fileName, increBatchSize, increSize, fileSize, minSup, increTotalSize, ReadNumTrans);

            //DateTime start = DateTime.Now;
            //ReadNumTrans = fileSize;
            //Eclat obj = new Eclat();
            //int minSupForCharm = (int)(fileSize * minSup);
            //obj.MINSUPPORT = minSupForCharm;
            //obj.READ_NUM_TRANS = ReadNumTrans;
            //obj.IS_INCRE = false;

            //obj.Run(args, fileName, "t1.txt");
            //Console.WriteLine("Trans {0} Nodes {1} Time {2}", ReadNumTrans, obj.maxtest.lattice.Count, (DateTime.Now - start).Milliseconds);


            //TestCLICL.Test();
            //Eclat newobj = new Eclat();
            //newobj.Run(args, "pumsb.txt", "t2.txt");
        }

        private static int OnlyCharmL(string[] args, string fileName, int fileSize, double minSup, int increSize, int ReadNumTrans) {
            Dictionary<int, long> dic = new Dictionary<int, long>();
            while (ReadNumTrans <= fileSize) {
                using (MyStopWatch sw = new MyStopWatch()) {
                    //DateTime start = DateTime.Now;
                    int minSupForCharm = (int)(fileSize * minSup);
                    Eclat obj = new Eclat();
                    obj.MINSUPPORT = minSupForCharm;
                    obj.READ_NUM_TRANS = ReadNumTrans;
                    obj.IS_INCRE = false;

                    obj.Run(args, fileName, "t1.txt", new Dictionary<int, long>());


                    Console.WriteLine("Trans " + ReadNumTrans + ".Time : ");
                    dic.Add(ReadNumTrans, sw.ElapsedMilliseconds);
                    ReadNumTrans += increSize;
                }
                Console.WriteLine("=================================================");
            }
            Console.WriteLine("=================================================");
            foreach (KeyValuePair<int, long> item in dic) {
                Console.WriteLine("Trans {0} Time {1}", item.Key, item.Value);
            }
            Console.WriteLine("=================================================");
            return ReadNumTrans;
        }

        private static int TestIncre(string[] args, string fileName, int increBatchSize, int increSize, int fileSize, double minSup, int increTotalSize, int ReadNumTrans) {
            Dictionary<int, long> dic = new Dictionary<int,long>();
            ReadNumTrans = fileSize - increTotalSize;
            int minSupForCharm = (int)(fileSize * minSup) - increTotalSize;

            while (ReadNumTrans <= fileSize) {
                using (MyStopWatch sw = new MyStopWatch()) {

                    Eclat obj = new Eclat();
                    obj.MINSUPPORT = minSupForCharm;
                    obj.READ_NUM_TRANS = ReadNumTrans;// -increBatchSize;
                    obj.IS_INCRE = true;
                    obj.INCRE_BATCH_SIZE = increBatchSize;
                    obj.INCRE_SIZE = increSize;
                    Console.WriteLine("CHARM-L");
                    obj.Run(args, fileName, "t2.txt", dic );
                    Console.WriteLine("Trans {0} Nodes {1} Time ", ReadNumTrans, obj.maxtest.lattice.Count);
                }
                ReadNumTrans += increBatchSize;
                Console.WriteLine("=================================================");
                minSupForCharm += increBatchSize;

            }
            return ReadNumTrans;
        }
    }
}
